@extends('Admin.base')
@section('css')
    <link rel="stylesheet" href="/Admin/layuiadmin/css/extend/formSelects-v4.css" media="all">
@endsection
@section('style')

@endsection
@section('content')

    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>补货记录</legend>
            </fieldset>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto ">
            <div class="layui-form-item layui-row">
                <div class="layui-col-md3" >
                    <div class="layui-input-block">
                        <label class="layui-form-label">日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="time"  autocomplete="off" class="layui-input" id="time-range" >
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">操作人:</label>
                    <div class="layui-input-block">
                        <input type="text" name="creater" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-btn-group layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-input-block layuiadmin-btn-admin" lay-submit lay-filter="LAY-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-table" lay-filter="LAY-table"></table>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn" lay-event="export">导 出</button>
                </div>
            </script>
            <script type="text/html" id="table-toolbar">
               <span> <a href="{{url('admin/store/')}}/@{{ d.id }}/padRecordDetail" class="layui-btn layui-btn-green layui-btn-xs">查看详情</a></span>
            </script>
        </div>
    </div>
@endsection
@section('script')
    <script src="/js/ajax.js"></script>
    <script>

        layui.use(['form', 'table','laydate', 'formSelects'], function(){
            var $ = layui.$
                    ,form = layui.form
                    ,table = layui.table
                    ,laydate = layui.laydate
            laydate.render({
                elem: '#time-range'
                ,type: 'date'
                ,range: true
            });

            var tableins = table.render({
                elem: '#LAY-table'
                ,title: "商品库存表"
                ,toolbar: "#toolbar"
                ,defaultToolbar: []
                ,id: 'list'
                ,width: 1200
                ,url: "{{route("store.padRecordTable")}}"
                ,method: "post"
                ,page: true
                ,limit:10
                ,cols: [[
                    {checkbox: true}
                    ,{field: 'created_at',width:200, title: '时间'}
                    ,{field: 'order_no', title: '补货单号'}
                    ,{field: 'd', title: '操作人',templet:function(d){
                        return d.adminer['username'];
                    }}
                    ,{field: 'skunum', title: '补货品类'}
                    ,{field: 'amount', title: '补货数量'}
                    ,{field: 'remark', title: '补货事由'}
                    ,{title: '操作', align: 'center', toolbar: '#table-toolbar'}
                ]]
            });
            //监听工具条
            table.on('toolbar(LAY-table)', function(obj){
                if(obj.event === 'export'){
                    var field = obj.config.where;
                    console.log(field);
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    var id_str = '';
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            id_str += data[i].id + ',';
                        }
                        id_str = id_str.substr(0, id_str.length-1);
                    }
                    layer.prompt({
                        id_str:id_str,
                        formType: 0,
                        value: '',
                        title: '请输入文件名称',
                        btn:['导出','取消']
                    }, function(value, index, elem){
                        if(value == '' || value == undefined){
                            layer.msg('请输入文件名称');
                        }else{
                            field.filename = value;
                            field.ids = id_str;
                            $.ajax({
                                url: '/admin/store/export'
                                , type: 'POST'
                                , dataType: 'json'
                                , data: field
                                , success: function (ret) {
                                    if (ret.hasOwnProperty('code') && ret.code == 200) {
                                        layer.msg(ret.message,{icon: 1,time:2000});
                                        return false;
                                    }
                                    layer.msg(ret.message,{icon:2});
                                }
                            });
                            layer.close(index);
                        }

                    });
                }

            });
            //监听搜索
            form.on('submit(LAY-search)', function(data){
                var field = data.field;
                console.log(field);
                //执行重载
                table.reload('list', {
                    where: field,page: {curr: 1}
                });

            });
            laydate.render({
                elem: '#date' //指定元素
            });

        });
    </script>

@endsection